<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:th="http://www.thymeleaf.org"
	  lang="zh-cn">
<head>
	<meta content="云之讯,云通讯,云通讯平台" name="keywords"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
	<title>短信云平台运营系统 - 销售财务</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
	<link th:href="@{/resources/css/bootstrap.min14ed.css?v=3.3.6}" href="/resources/css/bootstrap.min14ed.css" rel="stylesheet">
	<link th:href="@{/resources/css/font-awesome.min93e3.css?v=4.4.0}" href="/resources/css/font-awesome.min93e3.css" rel="stylesheet"><!-- jqgrid-->
	<link th:href="@{/resources/js/plugins/jqgrid/css/ui.jqgrid-bootstrap.css}" href="/resources/js/plugins/jqgrid/css/ui.jqgrid-bootstrap.css" rel="stylesheet">
	<link th:href="@{/resources/css/animate.min.css}" href="/resources/css/animate.min.css" rel="stylesheet">
	<link th:href="@{/resources/css/style.min862f.css?v=4.1.0}" href="/resources/css/style.min862f.css" rel="stylesheet">
	<link th:href="@{/resources/css/plugins/sweetalert/sweetalert.css}" href="/resources/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
	<link th:href="@{/resources/css/select2.css}" rel="stylesheet">
	<style>
		/* Additional style to fix warning dialog position */
		#alertmod_table_list_2 {
			top: 900px !important;
		}
		.fl{
			float: left;
		}
		.credit-title{
			width: 100%;
			height: 130px;
			box-sizing: border-box;
			padding: 10px;
		}
		.credit{
			width: 20%;
			height: 100%;
			border: 1px solid #ccc;
			border-right: none;
			text-align: center;

		}
		.credit-body{
			margin-top: 40px;
		}
		.bill{
			font-size: 20px;
			font-weight: 700;
		}
		.credit:hover{
		}
	</style>
</head>
<body class="gray-bg"><div th:replace="stat :: statCode"></div>
<div class="wrapper wrapper-content  animated fadeInRight">
	<div class="row">
		<div class="col-sm-12">
			<div class="tabs-container">

				<ul class="nav nav-tabs">
					<li th:if="${menus.wdsx}" class="active" id="agentTab1" ><a> 我的授信</a>
					</li>
					<li th:if="${menus.khsx}" class="" ><a href="/sellFinance/credit4Customer">客户授信</a>
					</li>
					<li th:if="${menus.khlssx}" class=""  ><a href="/sellFinance/customerHisCredit">客户历史授信</a>
					</li>
					<li th:if="${menus.xscw}" class="" ><a href="/sellFinance/saleFinance">销售财务</a>
					</li>
					<li th:if="${menus.xslscw}" class="" ><a  href="/sellFinance/salehisFinance">销售历史财务</a>
					</li>
					<li th:if="${menus.xssxzd}" class="" ><a  href="/sellFinance/saleCreditBill">销售授信账单</a>
					</li>
					<li th:if="${menus.khsxzd}" class="" ><a  href="/sellFinance/CustomerCreditBill">客户授信账单</a>
					</li>
				</ul>

				<div class="tab-pane active" th:if="${menus.wdsx}">
					<div class="panel-body">

						<div class="credit-title">
							<div class="fl credit">
								<div  class="credit-body">我的历史授信额度</div>
								<span class="bill"  th:text="${#numbers.formatDecimal(credit eq null?0:credit.financialHistoryCredit,1,4)}">0.0000</span><span>元</span>
							</div>
							<div class="fl credit">
								<div class="credit-body">我的历史授出额度</div>
								<span class="bill"  th:text="${#numbers.formatDecimal(credit eq null?0:credit.saleHistoryCredit,1,4)}">0.0000</span><span>元</span>
							</div>
							<div class="fl credit">
								<div class="credit-body">客户历史回款额度</div>
								<span class="bill"  th:text="${#numbers.formatDecimal(credit eq null?0:credit.agentHistoryPayment,1,4)}">0.0000</span><span>元</span>
							</div>
							<div class="fl credit">
								<div class="credit-body">我的授信余额</div>
								<span class="bill"  th:text="${#numbers.formatDecimal(credit eq null?0:credit.currentCredit,1,4)}">0.0000</span><span>元</span>
							</div>
							<div class="fl credit" style="border-right: 1px solid #ccc">
								<div class="credit-body">未回款额度</div>
								<span class="bill"  th:text="${#numbers.formatDecimal(credit eq null?0:credit.noBackPayment,1,4)}">0.0000</span><span>元</span>
							</div>
						</div>

						<form class="form-inline" method="post" id="mainForm" onkeydown="if(event.keyCode==13)return false;" style="margin-bottom:15px;">
							<div class="form-group m-r-md">
								<!--<input type="text" placeholder="订单号/产品ID/客户ID/代理商ID" name="condition" id="condition" class="form-control">-->
								<input type="text" placeholder="用户ID/用户名称" name="condition" id="condition" class="form-control" style="width: 246px;">
							</div>
							<div class="form-group">
								<label for="financialType">财务类型:</label>
								<select id="financialType" name="financialType" class="form-control ">
									<option value="">全部</option>
									<option value="0">入账</option>
									<option value="1">出账</option>
								</select>
							</div>
							<div class="form-group">
								<label for="businessType">业务类型:</label>
								<select id="businessType" name="businessType"  class="form-control">
									<option value="">全部</option>
									<option value="0">财务给我授信</option>
									<option value="1">财务降低我授信</option>
									<option value="2">我给客户授信</option>
									<option value="3">我降低客户授信</option>
									<option value="4">客户回款</option>
								</select>
							</div>

							<!-- 时间选择 -->
							<div class="form-group" id="sandbox-container" style="margin-left:2.5%">
								<div class="form-group pull-right">操作时间:
									<input placeholder="开始时间" class="form-control layer-date" name="startDateTime" id="startDateTime" />至
									<input placeholder="结束时间" class="form-control layer-date" name="endDateTime" id="endDateTime" />
								</div>
							</div>
							<div class="form-group" style="margin-top: 15px;">
								<span>&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-danger" onclick="search()">搜索</button></span>
								<span>&nbsp;&nbsp;<button type="button" class="btn btn-sm btn-primary" onclick="exportExcel()">导出Excel</button></span>
							</div>
						</form>

						<div class="ibox-content">
							<div class="jqGrid_wrapper">
								<table id="table_list"></table>
								<div id="pager_list"></div>
							</div>
							<p>&nbsp;</p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script th:src="@{/resources/js/jquery.min.js?v=2.1.4}"></script>
<script th:src="@{/resources/js/bootstrap.min.js?v=3.3.6}"></script>
<script th:src="@{/resources/js/content.min.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/layer/layer.js}"></script>
<script th:src="@{/resources/js/plugins/layer/laydate/laydate.js}"></script>
<script th:src="@{/resources/js/plugins/peity/jquery.peity.min.js}"></script>
<script th:src="@{/resources/js/plugins/jqgrid/js/i18n/grid.locale-cn.js}"></script>
<script th:src="@{/resources/js/plugins/jqgrid/js/jquery.jqGrid.min.js}"></script>
<script th:src="@{/resources/js/date_format.min.js?v=1.0.0}"></script>
<script th:src="@{/resources/js/plugins/sweetalert/sweetalert.min.js}"></script>
<script th:src="@{/resources/js/common.js?v=1.0.0}"></script>

<script th:inline="javascript">
    var max_export_num = [[${max_export_num}]];
    var msgTime=1500;
    // $("#startDateTime").val(laydate.now(-1));
    // $("#end_tim_day").val(laydate.now(-1));

    var start = {
        elem: "#startDateTime",
        format: "YYYY-MM-DD hh:mm",
        min: halfYearAgo("yyyy-MM-dd hh:mm"),
        max: laydate.now(),
        istoday: true,
        choose: function (datas) {
            end.min = datas;
        }
    };

    var end = {
        elem: "#endDateTime",
        format: "YYYY-MM-DD hh:mm",
        min: halfYearAgo("yyyy-MM-DD hh:mm"),
        max: laydate.now(),
        istoday: true,
        choose: function (datas) {
            start.max = datas;
        }
    };
    laydate(start);
    laydate(end);

    function search(){
        $("#table_list").jqGrid('setGridParam',{
            datatype:'json',
            postData: {
                condition: $("#condition").val(),
                financialType:$("#financialType").val(),
                businessType:$("#businessType").val(),
                startDateTime: $("#startDateTime").val(),
                endDateTime: $("#endDateTime").val()
            }, //发送数据
        }).trigger("reloadGrid"); //重新载入
    }

    // 导出Excel文件
    function exportExcel() {
        var totalCount = $("#table_list").jqGrid('getGridParam','records');
        if (totalCount == 0) {
            layer.alert("共0条记录，导出Excel文件失败");
            return;
        }
        if(totalCount > max_export_num){
            layer.msg("导出Excel文件条数大于"+max_export_num+"条", {icon: 2});
            return;
        }
        var mainForm = $("#mainForm");
        var action = mainForm.attr("action");
        var exporUrl = /*[[@{/sellFinance/myCredit/export}]]*/'';
        mainForm.attr("action", exporUrl).submit();
        mainForm.attr("action", action);
    }



    $(document).ready(function () {
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url:/*[[@{/sellFinance/myCredit/list}]]*/"",
            mtype: 'POST',
            datatype: "json",
            jsonReader : {
                root:"data.entityList",
                page: "data.currentPage",
                total: "data.totalPage",
                records: "data.totalCount"
            },
            postData: {
                condition: $("#condition").val(),
                financialType:$("#financialType").val(),
                businessType:$("#businessType").val(),
                startDateTime: $("#startDateTime").val(),
                endDateTime: $("#endDateTime").val()
            }, //发送数据
            height: 'auto',
            rownumbers:true,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            rowNum: 20,
            rowList: [10, 20, 30,50],
//            colNames: ["订单号","订单类型","产品ID","产品类型","产品总售价","产品总成本价","总数量","剩余数量","客户ID","代理商ID","状态","有效期（天）","到期时间","创建时间","操作"],
            colModel: [
                {label:'业务单号',name: "id",align: "left",sortable:false},
                {label:'业务类型',name: "businessTypeName",align: "left",sortable:false},
                {label:'财务类型',name: "financialTypeName",align: "left",sortable:false},
                {label:'账单金额（元）',name: "billamount",align: "left", sortable:false,formatter: "number", formatoptions: {thousandsSeparator:",", defaulValue:"",decimalPlaces:4}},
                {label:'用户ID',name: "objectId",align: "left",sortable:false},
                {label:'用户名称',name: "objectName",align: "left",sortable:false},
				{label:'用户类型',name: "objectTypeName",align: "left",sortable:false},
				{label:'操作者',name: "adminName",align: "left",sortable:false},
				{label:'备注',name: "remark",align: "left",sortable:false},
				{label:'操作时间',name: "createTimeStr",align: "left",sortable:false}
            ],
            pager:"#pager_list",
            viewrecords: true,
            hidegrid: false,
			/*统计功能 */
            footerrow:true,
            gridComplete:function(){
                var sum='';

                $.ajax({
                    type : "post",
                    url : /*[[@{/sellFinance/myCredit/total}]]*/'',
                    data : {
                        condition: $("#condition").val(),
                        financialType:$("#financialType").val(),
                        businessType:$("#businessType").val(),
                        startDateTime: $("#startDateTime").val(),
                        endDateTime: $("#endDateTime").val()
                    },
                    async:false,
                    success : function(result) {
                        if(result.code==0){
                            sum = Number(result.data).toFixed(4);
                        }else if(result.code==500){
                            layer.msg(result.msg, {icon: 2,time: msgTime});
                        }else{
                            layer.msg("计算总计失败", {icon: 2,time: msgTime});
                        }

                    }
                });
                $("#table_list").footerData('set', {
                    "id": '-',
                    "businessTypeName": '-',
                    "financialTypeName": '总计',
                    "billamount": sum,
                    "objectId": '-',
                    "objectName": '-',
                    "objectTypeName": '-',
                    "adminName": '-',
                    "remark": '-',
                    "createTime": '-'} );
            }
    });
        $(window).bind("resize", function () {
            var width = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(width);
        });

        function keyUp(e) {
            var currKey=0,e=e||event;
            currKey=e.keyCode||e.which||e.charCode;
            var keyName = String.fromCharCode(currKey);
            if (currKey == 13){
                search();
            }
        }
        document.onkeyup = keyUp;
    });
</script>

</body>
</html>